package com.example.yk

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.yk.adapter.SubmitAdapter
import com.example.yk.databinding.ActivityDetailBinding
import com.example.yk.entity.Re
import com.example.zk3.mvvm.BaseActivity

@Route(path = "/app/DetailActivity")
class DetailActivity : BaseActivity<ActivityDetailBinding,DettailViewModel>() {
    @JvmField
    @Autowired
    var id = 0

    val list = mutableListOf<Re>()
    lateinit var submitAdapter: SubmitAdapter
    override fun initData() {
        viewModel.success.observe(this){
            if(it.success){
                binding.detail = it.mallGoodsInfoInfo
            }
        }
        viewModel.submitSuccess.observe(this){
            if(it.success){
                list.clear()
                list.addAll(it.res)
                submitAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun initView() {
        ARouter.getInstance().inject(this)
        viewModel.detail(id)


        submitAdapter = SubmitAdapter(list)
        binding.submitRv.adapter = submitAdapter
        binding.submitRv.layoutManager = LinearLayoutManager( this)
        viewModel.submit(id)
    }

    override fun getLayout(): Int  = R.layout.activity_detail

    override fun getViewModel(): Class<DettailViewModel>  = DettailViewModel::class.java

}